using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using WozLib.UI.Ink.SketchProperties;

namespace WozLib.UI.Ink.SketchObjects
{


  [XmlInclude(typeof(ButtonSketchObject))]
  [XmlInclude(typeof(TextSketchObject))]
  [XmlInclude(typeof(EllipseSketchObject))]
  [XmlInclude(typeof(RectangleSketchObject))]
  [XmlInclude(typeof(LineSketchObject))]
  [XmlInclude(typeof(StrokeSketchObject))]
  public class SketchObject
  {
    [XmlAttribute("WozID")]
    public long WozID
    {
      get
      {
        return _WozID;
      }
      set
      {
        _WozID = value;
      }
    } private long _WozID;

    [XmlElement("WozProperties")]
    public List<SketchProperty> WozProperties
    {
      get
      {
        return _WozProperties;
      }
      set
      {
        _WozProperties = new List<WozLib.UI.Ink.SketchProperties.SketchProperty>(value);
      }
    } private List<SketchProperty> _WozProperties;

    public ISketchObject GetIWozObject(SketchObjectRegistry wozObjectRegistry)
    {
      if (wozObjectRegistry.ContainsObject(WozID))
      {
        return wozObjectRegistry.GetObject(WozID);
      }
      else
      {
        ISketchObject iWozObject = ISketchObjectFactory.FromWozObject(this, wozObjectRegistry);

        // don't need to make a call to the objectregistry because the objectfactory will do it for us
        //WozObjectRegistry.RegisterObjectWithExisitingId(iWozObject);

        return iWozObject;
      }
    }

    // gives it a new WozID
    public ISketchObject GetNewIWozObject(SketchObjectRegistry wozObjectRegistry)
    {
      ISketchObject iWozObject = ISketchObjectFactory.FromWozObjectNewID(this, wozObjectRegistry);

      // don't need to make a call to the objectregistry because the objectfactory will do it for us
      //WozObjectRegistry.RegisterObjectWithExisitingId(iWozObject);

      return iWozObject;
    }

    public SketchObject()
    {
    }

    public SketchObject(long wozID, IEnumerable<SketchProperty> wozProperties)
    {
      WozID = wozID;
      _WozProperties = new List<WozLib.UI.Ink.SketchProperties.SketchProperty>(wozProperties);
    }

    public SketchObject(long wozID, SketchProperty wozProperty)
    {
      WozID = wozID;
      _WozProperties = new List<WozLib.UI.Ink.SketchProperties.SketchProperty>();
      _WozProperties.Add(wozProperty);
    }
  }
}
